Code
pacman::p_load(slickR,
magick,
googledrive,
purrr,
fs,
bslib)pacman::p_load(slickR,
magick,
googledrive,
purrr,
fs,
bslib)Contents of envelope #1:
newlogo <- image_scale(image_read("https://jeroen.github.io/images/Rlogo.png"))
oldlogo <- image_scale(image_read("https://jeroen.github.io/images/Rlogo-old.png"))
image_resize(c(oldlogo, newlogo), '200x150!') %>%
image_background('white') %>%
image_morph() %>%
image_animate(optimize = TRUE)
# Download earth gif and make it a bit smaller for vignette
earth <- image_read("https://jeroen.github.io/images/earth.gif") %>%
image_scale("200x") %>%
image_quantize(128)
earth
rev(earth) %>%
image_flip() %>%
image_annotate("meanwhile in Australia", size = 20, color = "white")
# Foreground image
banana <- image_read("https://jeroen.github.io/images/banana.gif")
banana <- image_scale(banana, "150")
image_info(banana)# A tibble: 8 × 7
format width height colorspace matte filesize density
<chr> <int> <int> <chr> <lgl> <int> <chr>
1 GIF 150 148 sRGB TRUE 0 72x72
2 GIF 150 148 sRGB TRUE 0 72x72
3 GIF 150 148 sRGB TRUE 0 72x72
4 GIF 150 148 sRGB TRUE 0 72x72
5 GIF 150 148 sRGB TRUE 0 72x72
6 GIF 150 148 sRGB TRUE 0 72x72
7 GIF 150 148 sRGB TRUE 0 72x72
8 GIF 150 148 sRGB TRUE 0 72x72
# Background image
background <- image_background(image_scale(logo, "200"), "white", flatten = TRUE)
# Combine and flatten frames
frames <- image_composite(background, banana, offset = "+70+30")
# Turn frames into animation
animation <- image_animate(frames, fps = 10, optimize = TRUE)
print(animation)# A tibble: 8 × 7
format width height colorspace matte filesize density
<chr> <int> <int> <chr> <lgl> <int> <chr>
1 gif 200 150 sRGB FALSE 0 72x72
2 gif 94 100 sRGB FALSE 0 72x72
3 gif 125 117 sRGB FALSE 0 72x72
4 gif 108 113 sRGB FALSE 0 72x72
5 gif 108 100 sRGB FALSE 0 72x72
6 gif 92 100 sRGB FALSE 0 72x72
7 gif 113 118 sRGB FALSE 0 72x72
8 gif 119 113 sRGB FALSE 0 72x72

create_animation <- function(video_path, output_fps = 10, optimize = TRUE, output_path = "output.gif") {
# Read the video
video <- image_read_video(video_path)
# Turn frames into animation
animation <- image_animate(video, fps = output_fps, optimize = optimize)
# Print the animation
print(animation)
# Write the animation to a GIF file
image_write(animation, output_path)
cat("Animation saved as", output_path, "\n")
}
# Usage
demo_video_path <- "Site Image Reels Assets/PXL_20230911_004506245.TS~2.mp4"
create_animation(demo_video_path, output_path = "output.gif")list_of_videos <- fs::dir_ls(
'Site Image Reels Assets',
glob = "*.mp4"
)
# Vector of video filenames
envelope_loop_1_to_4 <- c(
"envelope1.gif",
"envelope2.gif",
"envelope3.gif",
"envelope4.gif"
)
# Iterate over the vector and create animations
purrr::walk2(list_of_videos,
envelope_loop_1_to_4,
\(x,y) create_animation(x,
output_path =
paste0('Site Image Reels Assets/gifs/',
y)
)
)Chonk: The Quest for Eternal Wisdom Chonk

list_of_gif <- fs::dir_ls(
'Site Image Reels Assets',
glob = "*.gif",
recurse = TRUE
)
# list_of_gif <- c("https://github.com/dar4datascience/Quarto-Example-Websites/blob/master/Site%20Image%20Reels%20Assets/gifs/envelope1.gif",
# "https://github.com/dar4datascience/Quarto-Example-Websites/blob/master/Site%20Image%20Reels%20Assets/gifs/envelope2.gif",
# "https://github.com/dar4datascience/Quarto-Example-Websites/blob/master/Site%20Image%20Reels%20Assets/gifs/envelope3.gif",
# "Site Image Reels Assets/gifs/envelope1.gif")
card(
card_header("Made with R"),
slickR(obj = list_of_gif,
height = 400,
objLinks = rep('Quarto%20Example%20Websites.html#sec-chonk-the-quest-for-eternal-wisdom-chonk',
length(list_of_gif)),
width = "95%") +
settings(dots = TRUE, autoplay = TRUE)
)